package com.lowang.okhttp3;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * Hello world!
 *
 */
public class App {
    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    static OkHttpClient client = new OkHttpClient();
    static String post(String url, String json) throws IOException {
        RequestBody body = RequestBody.create(JSON, json);
        Request request = new Request.Builder().url(url).post(body).build();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }
    static String get(String url) throws IOException {
        Request req = new Request.Builder().url(url).build();
        Response res = client.newCall(req).execute();
        String str = res.body().string();
        return str;
    }
    public static void main(String[] args) throws IOException {
        String str = post("http://www.baidu.com", "{}");
        System.out.println(str);
    }
}
